import { Component, OnInit }            from '@angular/core';
import { NzMessageService, NzModalRef } from 'ng-zorro-antd';
import { _HttpClient }                  from '@delon/theme';

@Component({
    selector   : 'app-pro-rest-password',
    templateUrl: './rest-password.component.html',
})
export class ProRestPasswordComponent implements OnInit
{
    
    pws = {
        oldPwd: "",
        newPwd: '',
        conPwd: ''
    };
    
    constructor(
        private modal: NzModalRef,
        private msgSrv: NzMessageService,
        public http: _HttpClient,
    )
    {}
    
    ngOnInit(): void
    {
    }
    
    save( value: any )
    {
        console.log(value);
        if ( value.newPwd !== value.conPwd )
        {
            this.msgSrv.error("新密码与确认密码不一致")
        }
        else
        {
            this.http.post("/api/users/rest-password", {
                oldPassword: value.oldPwd,
                newPassword: value.newPwd
            }).subscribe(() =>
            {
                this.msgSrv.info("密码修改成功");
                this.modal.destroy(true)
            })
        }
    }
    
    close()
    {
        this.modal.destroy();
    }
    
    
}
